﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BookDemo.S09.S901
{
    public class S901 : IBookDemo
    {
        public void Main(string[] args)
        {
            // Microsoft.Extensions.Logging
            // Microsoft.Extensions.Logging.Console
            // Microsoft.Extensions.Logging.Debug
            var logger = new ServiceCollection()
                  .AddLogging(builder => builder
                      .AddConsole()
                      .AddDebug())
                  .BuildServiceProvider()
                  .GetRequiredService<ILoggerFactory>()
                  .CreateLogger("App.Program");

            var levels = (LogLevel[])Enum.GetValues(typeof(LogLevel));
            levels = levels.Where(it => it != LogLevel.None).ToArray();
            var eventId = 1;
            Array.ForEach(levels, level => logger.Log(level, eventId++, "This is a/an {0} log message.", level));
        }
    }
}
